package czopyk.model.persistence.actions;

import czopyk.model.cost.DistributionId;
import czopyk.model.persistence.ValueExtractor;
import czopyk.model.structure.Modulator;

public class ChangeDistributionAction extends CommonAction implements Action {

	private final DistributionId id;
	private String params;
	private String offset;

	public ChangeDistributionAction(DistributionId id, String params,
			String offset, Modulator mod, ValueExtractor ve) {
		super(mod, ve);
		if (id == null) {
			throw new IllegalArgumentException("Distribution id cannot be null.");
		}
		this.id = id;
		this.params = params;
		this.mod = mod;
		this.offset = offset;
	}

	public void perform() {
		if (params != null) {
			String[] paramsArray = params.split(",");
			Double[] ps = new Double[paramsArray.length];
			for (int i = 0; i < paramsArray.length; ++i) {
				ps[i] = ve.getNumber(paramsArray[i].trim()).doubleValue();
			}
		}

		if (offset != null) {
			mod.changeDistributionOffset(id, ve.getNumber(offset).doubleValue());
		}
	}
}
